package aufg3;

public class RandVar {
	// pdf = probability density function

	double mean;
	double variance;
	double coefﬁcientOfVariation;
	double[] randomNumbers;
	StdRNG stdRNG;

	public RandVar() {
		this.mean = 0;
		this.variance = 0;
		this.coefﬁcientOfVariation = 0;
		this.stdRNG = new StdRNG(0);
	}

	protected void reset() {
		this.mean = 0;
		this.variance = 0;
		this.coefﬁcientOfVariation = 0;
	}

	private double[] getRV(int sizeOfArray) {
		this.randomNumbers = new double[sizeOfArray];
		for (int i = 0; i < this.randomNumbers.length; i++) {
			this.randomNumbers[i] = this.stdRNG.getNextRandomNumber();
			// this.stdRNG.setSeed(i);
		}
		return randomNumbers;
	}

	public double calculateCoefﬁcientOfVariation() {
		reset();
		double mean = calculateMean();
		double variance = calculateVariance();
		double stdAbweichung = Math.sqrt(variance);

		return this.coefﬁcientOfVariation = stdAbweichung / mean;
	}

	public double calculateMean() {
		reset();
		long sizeOfArray = this.randomNumbers.length;
		for (double number : this.randomNumbers) {
			mean += number;
		}
		return mean / sizeOfArray;
	}

	public double calculateVariance() {
		reset();
		long sizeOfArray = this.randomNumbers.length;
		double dasMean = calculateMean();

		for (double number : this.randomNumbers) {
			variance += quadrat((number - dasMean));
		}

		return variance / sizeOfArray;
	}

	protected double quadrat(double number) {
		return number * number;
	}

	// private double getStandardAbweichung(){
	// reset();
	// getVariance();
	// return Math.sqrt(variance);
	// }

	public void setCoefﬁcientOfVariation(double coefﬁcientOfVariation) {
		this.coefﬁcientOfVariation = coefﬁcientOfVariation;
	}

	public void setMean(double mean) {
		this.mean = mean;
	}

	public void setVariance(double variance) {
		this.variance = variance;
	}

	public void setRandomNumbers(double[] randomNumbers) {
		this.randomNumbers = randomNumbers;
	}
	
	public double[] getRandomNumbers() {
		return randomNumbers;
	}
	
	public String numberArrayToString(){
		String o = "";
		for (double n : this.randomNumbers) {
			o += n + " ,";
		}
		return o;
	}
	
	public double getCoefﬁcientOfVariation() {
		return coefﬁcientOfVariation;
	}
	
	public double getMean() {
		return mean;
	}
	

	// main zum dynamischen testen
	public static void main(String[] args) {
		RandVar rV = new RandVar();

		// for (double number : rV.receiveRandomNumbers(10)) {
		// System.out.println(number);
		// }

		double[] bla = { 0, 1, 2, 3.0 };
		rV.setRandomNumbers(bla);

		System.out.println(rV.calculateMean());
		System.out.println(rV.calculateVariance());
		System.out.println(rV.calculateCoefﬁcientOfVariation());
	}
}
